function stackTraceHere() {
    var Exception = Java.use('java.lang.Exception');
    var Log = Java.use('android.util.Log');
    console.log(Log.getStackTraceString(Exception.$new()))
}

var data = null; // Global variable to store the extracted data
var appid = null;

function url() {
    console.log(data);
};

function getAppid() {
    console.log(appid);
}

Java.perform(function () {

    var String = Java.use("java.lang.String");
    // console.log("hook start");
    let Log = Java.use("com.tencent.mm.sdk.platformtools.Log");
    Log["i"].overload('java.lang.String', 'java.lang.String', '[Ljava.lang.Object;').implementation = function (str, str2, objArr) {
        // console.log('[*] i: Log.i is called' + ', ' + 'str: ' + str + ', ' + 'str2: ' + str2 + ', ' + 'objArr: ' + objArr);
        // Check if the string contains "appentrypage"
        if (str2.includes("appentrypage")) {
            // console.log('[*] i: Log.i is called' + ', ' + 'str: ' + str + ', ' + 'str2: ' + str2 + ', ' + 'objArr: ' + objArr);

            // Use a regular expression to extract the appentrypage value
            var match = /<appentrypage><!\[CDATA\[(.*?)\]\]><\/appentrypage>/.exec(str2);
            if (match && match[1]) {
                data = match[1]; // Store the extracted value in data
            }

            var appIdMatch = /<appid><!\[CDATA\[(.*?)\]\]><\/appid>/.exec(str2);
            if (appIdMatch && appIdMatch[1]) {
                appid = appIdMatch[1]; // Store the extracted value in data
            }
            // console.log(data);
            // console.log(appid);
        }
        this["i"](str, str2, objArr);
    };

    // Log["d"].overload('java.lang.String', 'java.lang.String', '[Ljava.lang.Object;').implementation = function (str, str2, objArr) {
    //     console.log('[*] d: Log.i is called' + ', ' + 'str: ' + str + ', ' + 'str2: ' + str2 + ', ' + 'objArr: ' + objArr);
    //     // Check if the string contains "appentrypage
    //     this["d"](str, str2, objArr);
    // };
    //
    // Log["v"].overload('java.lang.String', 'java.lang.String', '[Ljava.lang.Object;').implementation = function (str, str2, objArr) {
    //     console.log('[*] v: Log.i is called' + ', ' + 'str: ' + str + ', ' + 'str2: ' + str2 + ', ' + 'objArr: ' + objArr);
    //     // Check if the string contains "appentrypage
    //     this["v"](str, str2, objArr);
    // };
    //
    // Log["e"].overload('java.lang.String', 'java.lang.String', '[Ljava.lang.Object;').implementation = function (str, str2, objArr) {
    //     console.log('[*] e : Log.i is called' + ', ' + 'str: ' + str + ', ' + 'str2: ' + str2 + ', ' + 'objArr: ' + objArr);
    //     // Check if the string contains "appentrypage
    //     this["e"](str, str2, objArr);
    // };

});

// 冷启动小程序 8.0.10
// function startMiniAppOld(appid) {
//     let AppBrandLaunchProxyUI = Java.use("com.tencent.mm.plugin.appbrand.launching.AppBrandLaunchProxyUI");
//     var current_application = Java.use('android.app.ActivityThread').currentApplication();
//     var context = current_application.getApplicationContext();
//     let AppBrandStatObject = Java.use("com.tencent.mm.plugin.appbrand.report.AppBrandStatObject");
//     var appBrandStatObject = AppBrandStatObject.$new();
//     // wx2baa829fa4852ed7 qq阅读 wx78ccd192f4dedcab 传音科技 wxbebb3cdd9b331046 国务院
//     AppBrandLaunchProxyUI["a"](context, null, appid, null, 0, -1, appBrandStatObject, null, null);
// }
function startMiniAppOld(appid) {
    // 使用Java.use方法获取AppBrandLaunchProxyUI类
    let AppBrandLaunchProxyUI = Java.use("com.tencent.mm.plugin.appbrand.launching.AppBrandLaunchProxyUI");
    // 使用Java.use方法获取ActivityThread类
    var current_application = Java.use('android.app.ActivityThread').currentApplication();
    // 获取当前应用程序的上下文
    var context = current_application.getApplicationContext();
    // 使用Java.use方法获取AppBrandStatObject类
    let AppBrandStatObject = Java.use("com.tencent.mm.plugin.appbrand.report.AppBrandStatObject");
    // 创建AppBrandStatObject对象
    var appBrandStatObject = AppBrandStatObject.$new();
    // 调用AppBrandLaunchProxyUI类的z6方法，启动小程序，微信8.0.49版本
    // wx2baa829fa4852ed7 qq阅读 wx78ccd192f4dedcab 传音科技 wxbebb3cdd9b331046 国务院
    AppBrandLaunchProxyUI["z6"](context, null, appid, null, 0, -1, appBrandStatObject, null, null);
}

rpc.exports = {
    getUrl: function () {
        if (data === null) {
            return null;
        } else {
            // Return the extracted data
            return data.toString();
        }
    },
    getAppid: function () {
        if (appid === null) {
            return null;
        } else {
            // Return the extracted data
            return appid.toString();
        }
    },
    startMiniApp: startMiniAppOld
};






